//
// Created by 11510 on 2024/6/6.
//
#include <iostream>
#include <string.h>
using namespace std;

class Student{
public:
    Student(int id, const char *name)
    :_id(id), _name(new char[strlen(name) + 1]){
        strcpy(_name, name);
    }
    ~Student(){
        if(_name){
            delete [] _name;
            _name = nullptr;
        }
    }

    Student(const Student &rhs)
    :_id(rhs._id),_name(new char[strlen(rhs._name) + 1]){
        strcpy(_name, rhs._name);
    }

    Student &operator=(const Student &rhs){
        if(this != &rhs){
            delete [] _name;
            _name = new char[strlen(rhs._name) + 1]();
            strcpy(_name, rhs._name);
            _id = rhs._id;
        }
        return *this;
    }
    void toString(){
        cout << "stu id:" << _id << endl;
        cout << "stu name:" << _name << endl;
    }

    void destroy(){
        delete this;
    }


private:
    int _id;
    char *_name;
};


void test0(){
    Student s1(1, "Jack Chen");
    s1.toString();

}

int main(void){
    test0();
    return 0;
}
